# -*- coding = utf-8 -*-
# @Time      : 2020/10/17 19:44
# @Author    : Reanon
# @File      : saveData.py
# @Email     : dafo360@gmail.com
# @Software  : PyCharm
# 正则表达式，进行文字匹配
# 指定URL，获取网页数据

# 进行excel操作
import xlwt


def saveData(datalist, savepath):
    """
    保存数据
    :param savepath:
    :return:
    """
    # 创建workbook 对象,设置样式压缩效果
    book = xlwt.Workbook(encoding='utf-8', style_compression=0)
    # 创建工作表sheet,可以覆盖
    sheet = book.add_sheet('豆瓣电影250', cell_overwrite_ok=True)
    # 定义列名
    col = ("Hardware Vendor", "System Enclosure", "HTML", "Text", "Nodes", "JVM Vendor", "CPU Description", "MHz",
           "Chips",
           "Total Threads", "Total Memory (GB)", "ssj_ops @ 100%", "avg. watts @ 100%", "avg. watts@ active idle",
           "Result (Overall ssj_ops/watt)")
    for i in range(0, len(col)):
        # 写入列名
        sheet.write(0, i, col[i])

    for i in range(0, len(datalist)):
        print("第%d条" % i)
        data = datalist[i]
        for j in range(0, len(col)):
            sheet.write(i + 1, j, data[j])

    print("爬取完毕")
    # 保存数据
    book.save(savepath)
